define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pro/appoint/index',
                    add_url: 'pro/appoint/add',
                    edit_url: 'pro/appoint/edit',
                    del_url: 'pro/appoint/del',
                    multi_url: 'pro/appoint/multi',
                    table: 'gzns_user_appoint',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showColumns: false,
                showToggle: false,
                showExport: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'nickname',align:"left", operate: 'LIKE',title: __('用户信息'),formatter: function (value, row, index) {
                            if(row.user.nick_name){
                                var image = '<a href="'+row.user.avatar+'" target="_blank"><img class="img-sm img-center" src="'+row.user.avatar+'"></a>'
                                return image + " "+row.nickname+(row.phone?'【'+row.phone+'】':'');
                            }else{
                                return "未绑定"
                            }
                        }},
                        {field: 'title', title: __('Title'), operate:false},
                        {field: 'status', title: __('问题状态'), searchList: {"0":__('已取消'),"1":__('待受理'),"2":__('受理中'),"3":__('已完成')}, formatter: Table.api.formatter.normal},
                        {field: 'is_public', title: __('是否公开'), searchList: {"0":__('不是'),"1":__('公开')}, formatter: Table.api.formatter.normal},
                        {field: 'is_recommend', title: __('关闭/推荐'), searchList: {"0":__('关闭'),"1":__('推荐')}, formatter: Table.api.formatter.toggle},
                        {field: 'create_time', title: __('Create_time'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});